require "rubygems"
require "eventmachine"
require "memcache"

@cache = MemCache.new(['127.0.0.1:11011'],:namespace=>"XQ#{@local_ip}")

EM.run{
  p 'EM.run 1st block.'
  EM.add_periodic_timer(5){
    @cache.set :Timer1,"Time now => #{Time.now.to_s}"
    p 'set Timer1'
  }
  
  EM.add_periodic_timer(5){
    puts @cache.get(:Timer1)
  }
  
  EM.add_periodic_timer(7){
    @cache.set :Timer2,"Hello dear All. I'm logger :)"
    p 'set Timer2'
  }
  
  EM.add_periodic_timer(7){
    puts @cache.get(:Timer2)
  }
}

EM.run{
  p 'EM.run 2nd block.'
  EM.add_periodic_timer(3){
    @cache.set :Timer3,"Time now => #{Time.now.to_s}"
    p 'set Timer1'
  }
  
  EM.add_periodic_timer(3){
    puts @cache.get(:Timer1)
  }
}